package com.apex.crm.controller;

import com.apex.crm.base.BaseController;
import com.apex.crm.service.UserService;
import com.apex.crm.utils.CookieUtil;
import com.apex.crm.utils.LoginUserUtil;
import com.apex.crm.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author XiaoYang
 * @version 1.0
 * @program: crm
 * @Classname IndexController
 * @description TODO
 * @date 2021/4/20 9:16
 */

@Controller
public class IndexController extends BaseController {

    @Resource
    private UserService userService;

    //系统登录页
    @RequestMapping("index")
    public String index(){
        return "index";
    }

    //系统欢迎页
    @RequestMapping("welcome")
    public String welcome(){
        return "welcome";
    }

    //后台管理页
    @RequestMapping("main")
    public String main(HttpServletRequest request){
        Integer userId= LoginUserUtil.releaseUserIdFromCookie(request);
        User user = userService.selectByPrimaryKey(userId);
        request.getSession().setAttribute("user",user);
        //System.out.println(userId);
        //System.out.println(user);
        //System.out.println(request);
        //System.out.println(CookieUtil.getCookieValue(request,"userId"));
        return "main";
    }





}
